package com.lin.filegraph.utils.parser.node;

import org.eclipse.jdt.core.dom.ASTNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:26
 */

public class JInterfaceNode extends JTypeNode {

    private List<JTypeNode> listSonTypeNodes = new ArrayList<>();

    public JInterfaceNode(String filePath, ASTNode astNode, String interfaceName, String modifier, String strOuterType, List<String> listStrSuperInterface) {
        super(filePath, astNode, interfaceName, modifier, strOuterType, listStrSuperInterface);
    }

    public List<JTypeNode> getListSonTypeNodes() {
        return listSonTypeNodes;
    }

    public void addSonTypeNode(JTypeNode sonTypeNode) {
        this.listSonTypeNodes.add(sonTypeNode);
    }

    public List<JClassNode> getListClassImplements() {
        List<JClassNode> listClassImplements = new ArrayList<>();
        for (JTypeNode typeNode : listSonTypeNodes) {
            if (typeNode instanceof JClassNode) {
                listClassImplements.add((JClassNode) typeNode);
            }
        }
        return listClassImplements;
    }

    public List<JEnumNode> getListEnumImplements() {
        List<JEnumNode> listEnumImplements = new ArrayList<>();
        for (JTypeNode typeNode : listSonTypeNodes) {
            if (typeNode instanceof JEnumNode) {
                listEnumImplements.add((JEnumNode) typeNode);
            }
        }
        return listEnumImplements;
    }

    public List<JInterfaceNode> getListSonInterfaces() {
        List<JInterfaceNode> listSonInterfaces = new ArrayList<>();
        for (JTypeNode typeNode : listSonTypeNodes) {
            if (typeNode instanceof JInterfaceNode) {
                listSonInterfaces.add((JInterfaceNode) typeNode);
            }
        }
        return listSonInterfaces;
    }

    @Override
    public String toString() {
        return "[InterfaceNode] " + getTypeName() + "  StartLine: " + getStartLine();
    }

    @Override
    public void displayStrInheritance() {
        // TODO Auto-generated method stub
        if (!getListStrSuperInterface().isEmpty()) {
            System.out.println(this);
            if (!getListStrSuperInterface().isEmpty()) {
                System.out.println("    StrSuperInterfaces:" + getListStrSuperInterface());
            }
        }
    }
}

